package com.spic.business.ioc.service.impl;

import com.spic.business.ioc.domain.IocHazardousWasteTreatment;
import com.spic.business.ioc.mapper.IocHazardousWasteTreatmentMapper;
import com.spic.business.ioc.service.IIocHazardousWasteTreatmentService;
import com.spic.common.core.domain.R;
import com.spic.common.core.utils.StringUtils;
import com.spic.common.core.utils.UUIDUtil;
import com.spic.system.api.RemoteDictDataService;
import com.spic.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 危废物处置情况数据IOCService业务层处理
 *
 * @author spic
 * @date 2022-04-14
 */
@Service
public class IocHazardousWasteTreatmentServiceImpl implements IIocHazardousWasteTreatmentService
{
    @Autowired
    private IocHazardousWasteTreatmentMapper iocHazardousWasteTreatmentMapper;

    @Autowired
    private RemoteDictDataService remoteDictDataService;
    /**
     * 查询危废物处置情况数据IOC
     *
     * @param id 危废物处置情况数据IOC主键
     * @return 危废物处置情况数据IOC
     */
    @Override
    public IocHazardousWasteTreatment selectIocHazardousWasteTreatmentById(String id)
    {
        return iocHazardousWasteTreatmentMapper.selectIocHazardousWasteTreatmentById(id);
    }

    /**
     * 查询危废物处置情况数据IOC列表
     *
     * @param iocHazardousWasteTreatment 危废物处置情况数据IOC
     * @return 危废物处置情况数据IOC
     */
    @Override
    public List<IocHazardousWasteTreatment> selectIocHazardousWasteTreatmentList(IocHazardousWasteTreatment iocHazardousWasteTreatment)
    {
        return iocHazardousWasteTreatmentMapper.selectIocHazardousWasteTreatmentList(iocHazardousWasteTreatment);
    }

    /**
     * 新增危废物处置情况数据IOC
     *
     * @param iocHazardousWasteTreatment 危废物处置情况数据IOC
     * @return 结果
     */
    @Override
    public int insertIocHazardousWasteTreatment(IocHazardousWasteTreatment iocHazardousWasteTreatment)
    {
        if(StringUtils.isNotEmpty(iocHazardousWasteTreatment.getType()))
        {
            R<List<SysDictData>> monitoring_location_type = remoteDictDataService.getDictDataByDictType("waste_type");
            List<SysDictData> dictList = monitoring_location_type.getData();

            for (SysDictData dict : dictList)
            {
                //分类列表数据
                if (dict.getDictValue().equals(iocHazardousWasteTreatment.getType()))
                {
                    iocHazardousWasteTreatment.setTypeName(dict.getDictLabel());
                    break;
                }
            }
        }
        String uuid = UUIDUtil.createUUID();
        iocHazardousWasteTreatment.setId(uuid);
        return iocHazardousWasteTreatmentMapper.insertIocHazardousWasteTreatment(iocHazardousWasteTreatment);
    }

    /**
     * 修改危废物处置情况数据IOC
     *
     * @param iocHazardousWasteTreatment 危废物处置情况数据IOC
     * @return 结果
     */
    @Override
    public int updateIocHazardousWasteTreatment(IocHazardousWasteTreatment iocHazardousWasteTreatment)
    {
        if(StringUtils.isNotEmpty(iocHazardousWasteTreatment.getType()))
        {
            R<List<SysDictData>> monitoring_location_type = remoteDictDataService.getDictDataByDictType("waste_type");
            List<SysDictData> dictList = monitoring_location_type.getData();

            for (SysDictData dict : dictList)
            {
                //分类列表数据
                if (dict.getDictValue().equals(iocHazardousWasteTreatment.getType()))
                {
                    iocHazardousWasteTreatment.setTypeName(dict.getDictLabel());
                    break;
                }
            }
        }
        return iocHazardousWasteTreatmentMapper.updateIocHazardousWasteTreatment(iocHazardousWasteTreatment);
    }

    /**
     * 批量删除危废物处置情况数据IOC
     *
     * @param ids 需要删除的危废物处置情况数据IOC主键
     * @return 结果
     */
    @Override
    public int deleteIocHazardousWasteTreatmentByIds(String[] ids)
    {
        return iocHazardousWasteTreatmentMapper.deleteIocHazardousWasteTreatmentByIds(ids);
    }

    /**
     * 删除危废物处置情况数据IOC信息
     *
     * @param id 危废物处置情况数据IOC主键
     * @return 结果
     */
    @Override
    public int deleteIocHazardousWasteTreatmentById(String id)
    {
        return iocHazardousWasteTreatmentMapper.deleteIocHazardousWasteTreatmentById(id);
    }

    /**
     * @return 危废物处置情况数据
     */

    @Override
    public List<Map<String, Object>> getHazardousWasteTreatment()
    {
        return null;
    }
}
